local weihan = fk.CreateSkill {
  name = "ls__weihan",
  tags = { "Round" }
}

Fk:loadTranslationTable{
  ["ls__weihan"] = "威捍",
  [":ls__weihan"] = "其他角色的回合结束时，你可摸一张牌并令其<a href='lvs__leave'>调离</a>，直到其回合开始或你受到一次伤害，期间此技能无效。",
  ["#ls__weihan-invoke"] = "威捍：你可摸一张牌并令%src调离",

  ["$ls__weihan1"] = "拔山扛鼎，力敌千钧。",
  ["$ls__weihan2"] = "好大口气，我定要取汝囚首。",
}

local DIY = require "packages/diy_utility/diy_utility"

weihan:addEffect(fk.TurnStart, {
  anim_type = "offensive",
  can_refresh = function(self, event, target, player, data)
    return table.contains(target:getTableMark("weihan_buff"), player.id)
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:removeTableMark(target, "weihan_buff", player.id)
    player.room:validateSkill(player, weihan.name, "", weihan.name)
    DIY.returnPlayer(target, "ls__weihan")
  end,
})

weihan:addEffect(fk.TurnEnd, {
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(weihan.name) and target ~= player
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askToSkillInvoke(player, { skill_name = weihan.name, prompt = "#ls__weihan-invoke:".. target.id })
  end,
  on_use = function(self, event, target, player, data)
    DIY.removePlayer(target, "ls__weihan")
    player.room:addTableMark(target, "weihan_buff", player.id)
    player.room:invalidateSkill(player, weihan.name, "", weihan.name)
    player:drawCards(1, weihan.name)
  end,
})

weihan:addEffect(fk.Damaged, {
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(weihan.name, true, true) and target == player
  end,
  on_refresh = function(self, event, target, player, data)
    for _, p in ipairs(player.room:getAlivePlayers()) do
      if table.contains(p:getTableMark("weihan_buff"), player.id) then
        player.room:removeTableMark(p, "weihan_buff", player.id)
        DIY.returnPlayer(p, "ls__weihan")
      end
    end
    player.room:validateSkill(player, weihan.name, "", weihan.name)
  end,
})

return weihan